package pl.edu.pw.perg.compinfodb.ui;

import java.awt.Component;

import javax.swing.JTree;

import org.springframework.richclient.image.IconSource;
import org.springframework.richclient.tree.FocusableTreeCellRenderer;

import pl.edu.pw.perg.compinfodb.datamodel.SelectableTreeNode;

@SuppressWarnings("serial")
public class EquipmentTreeCellRenderer extends FocusableTreeCellRenderer {

	private IconSource iconSource;
	
	public EquipmentTreeCellRenderer(IconSource is){
		iconSource = is;
	}
	
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
				row, hasFocus);
		SelectableTreeNode node = (SelectableTreeNode) value;
		if (node.isRoot()) {
			this.setIcon(iconSource.getIcon("cms.bullet"));
		} else {
			this.setText(node.getUserObject().toString());
			// TODO: wyszarzanie jesli bez elementow
			// if(o.)
			if (!node.isSelected()) {

				this.setIcon(iconSource.getIcon("not_selected.bullet"));
			} else if (node.isSelected()) {
				this.setIcon(iconSource.getIcon("selected.bullet"));
			}

		}
		return this;
	}

}
